home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / fluidsVerifyGrid.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.6 KB  |  183 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  May 2000 
  22. //
  23. //
  24. //
  25. //  Procedure Name:
  26. //         fluidsVerifyGrid
  27. //
  28. //  Description:
  29. //        Verifies that selected fluids have either static or
  30. //        dynamic (as appropriate) grids for the $current
  31. //        property.  Values of $current are expected to be UI
  32. //        names of paintable fluid attributes, such as those
  33. //        listed in the $paintProperties array below.  We do
  34. //        it this way, since it's also ok to pass in
  35. //        combinations of these attributes, as in
  36. //        "colorAndDensity".
  37. //        
  38. //  Return Value:
  39. //      "true" if property $current is set to either static or
  40. //         dynamic grid.  $makeGridCmd is unchanged.
  41. //
  42. //      "false" if property $current is not set to either static or
  43. //         dynamic grid.  $makeGridCmd[0] contains the MEL command 
  44. //        to set active fluids to dynamic grid.  $makeGridCmd[1] is
  45. //        the MEL command to make them static.
  46. //
  47. global proc int activeFluidsVerifyGrid( string $current, 
  48.                                         string $makeGridCmd[] )
  49. //
  50. // Description:
  51. //    For active fluids, call fluidsVerifyGrid.
  52. //    
  53. {
  54.     int $result = true;
  55.  
  56.     string $selectedFluids[] = `getActiveFluidShapes`;
  57.     if( size( $selectedFluids ) > 0 ) {
  58.         for( $fluid in $selectedFluids ) {
  59.             if( !fluidsVerifyGrid( $fluid, $current, $makeGridCmd ) ) {
  60.                 $result = false;
  61.             }
  62.         }
  63.     }
  64.     
  65.     return $result;
  66. }        
  67.  
  68.  
  69. global proc int fluidsVerifyGrid( string $fluid, 
  70.                                   string $current, 
  71.                                   string $makeGridCmd[] )
  72. {
  73.     $current = tolower( $current );
  74.  
  75.     string $ctx = `currentCtx`;
  76.     int    $ok = true;
  77.  
  78.     // These are the settings for the artFluidAttrCtx cmd.
  79.     // Note that we don't worry about combinations of properties
  80.     // (like "colorAndDensity" since we'll test those individually
  81.     // based on matching the single property name.
  82.     //
  83.     // When adding a paint property here, make sure the lengths of
  84.     // all four arrays are kept in sync.
  85.     //
  86.     string $paintProperties[] = { "density", 
  87.                                   "color", 
  88.                                   "temperature",
  89.                                   "fuel",
  90.                                   "velocity",
  91.                                   "textureCoordinates" };
  92.  
  93.     // These are the fluid attribute names to check for grid status for
  94.     // the above corresponding paint context properties.
  95.     //
  96.     string $fluidAttributes[] = { ".densityMethod", 
  97.                                   ".colorMethod",
  98.                                   ".temperatureMethod",
  99.                                   ".fuelMethod",
  100.                                   ".velocityMethod",
  101.                                   ".coordinateMethod" };
  102.                                   
  103.     // The min/max numeric value for each of the above fluid attributes
  104.     // that corresponds to a Grid valued-attribute.  Notice for 
  105.     // attributes that don't support static grids (fuel and textureCoords)
  106.     // we're just using a value that's the same as the dynamic value.
  107.     //
  108.     int $staticValues[] = { 1,        // densityMethod
  109.                             1,        // colorMethod
  110.                             1,        // temperatureMethod
  111.                             2,        // fuelMethod
  112.                             1,      // velocityMethod
  113.                             1 };    // textureCoordinates
  114.  
  115.     int $dynamicValues[] = { 2,        // densityMethod
  116.                              2,        // colorMethod
  117.                              2,        // temperatureMethod
  118.                              2,        // fuelMethod
  119.                              2,        // velocityMethod
  120.                              1 };    // textureCoordinates
  121.                                   
  122.     // Keep track of the commands we might need to 
  123.     // execute for static/dynamic grids individually.  (We'll
  124.     // need one or the other depending on the response from
  125.     // the confirm box below.) 
  126.     //
  127.     string $createDynamic;
  128.     string $createStatic;
  129.  
  130.     int $i = 0;
  131.     int $numMatches = 0;
  132.  
  133.     for( ; $i < size( $paintProperties ); $i++ ) {
  134.         if( size( match( tolower($paintProperties[$i]), tolower($current) ) ) ) {
  135.             int $method = eval( "getAttr " + $fluid + $fluidAttributes[$i] );
  136.             $numMatches++;
  137.             
  138.             // This property is already set to grid.
  139.             //
  140.             if(( $method == $staticValues[$i] )
  141.             || ( $method == $dynamicValues[$i] ))
  142.             {
  143.                 continue;
  144.             }
  145.  
  146.             $ok = false;
  147.  
  148.             // The static value is the same as the dynamic value --
  149.             // only show "Dynamic Grid" option
  150.             //
  151.             if(( $staticValues[$i] != $dynamicValues[$i] )) {
  152.                 $createStatic = $createStatic + ( "setAttr " + 
  153.                                                   $fluid + 
  154.                                                   $fluidAttributes[$i] + 
  155.                                                   " " +
  156.                                                   $staticValues[$i] + "; " );
  157.             }
  158.             
  159.             $createDynamic = $createDynamic + ( "setAttr " + 
  160.                                                 $fluid +
  161.                                                 $fluidAttributes[$i] + 
  162.                                                 " " +
  163.                                                 $dynamicValues[$i] + "; " );
  164.         }
  165.     }
  166.     
  167.     // If they're painting combinations (color + density,
  168.     // for instance) then we're just going to make it easier
  169.     // on ourselves and forget about the fact that color doesn't
  170.     // really have a "static grid" mode by removing the "set static" 
  171.     // option from the confirm box.
  172.     //
  173.     if( $numMatches > 1 ) {
  174.         $createStatic = "";
  175.     }
  176.  
  177.     $makeGridCmd[0] = $makeGridCmd[0] + $createDynamic;
  178.     $makeGridCmd[1] = $makeGridCmd[1] + $createStatic;
  179.     
  180.     return $ok;
  181. }
  182.  
  183.